﻿using System;
using System.Collections.Generic;
using UnityEditor;

namespace Assets.Scripts.Editor
{
    /// <summary>
    /// 打包工具
    /// </summary>
    public class ProjectBuild : UnityEditor.Editor {


        //在这里找出你当前工程所有的场景文件，假设你只想把部分的scene文件打包 那么这里可以写你的条件判断 总之返回一个字符串数组。
        static string[] GetBuildScenes()
        {
            List<string> names = new List<string>();
            foreach (EditorBuildSettingsScene e in EditorBuildSettings.scenes)
            {
                if (e == null)
                    continue;
                if (e.enabled)
                    names.Add(e.path);
            }
            return names.ToArray();
        }

        [MenuItem("Build/All")]
        static void BuildAll()
        {
            BuildSCGETVIDEOVersion();
            BuildSCGETVIDEOVersionTest();
        }

        [MenuItem("Build/IAClient")]
        static void BuildSCGETVIDEOVersion()
        {
            string path = @"F:\软件发布包\智能化\正式\太学智能化考核系统.exe";
            Building(path, "太学智能化考核系统", "");
        }



        [MenuItem("Build/IAClient(Test)")]
        static void BuildSCGETVIDEOVersionTest()
        {
            string path = @"F:\软件发布包\智能化\测试\太学智能化考核系统(Test).exe";
            Building(path, "太学智能化考核系统", "TEST");
        }

        static void Building(string path, string productName, string define)
        {
            string defines = define;
            PlayerSettings.fullScreenMode = UnityEngine.FullScreenMode.Windowed;
            PlayerSettings.companyName = "zjtaixue";
            PlayerSettings.productName = productName + GetBundleVersion();
            // PlayerSettings.applicationIdentifier = "unity.zjtaixue." + productName;
            PlayerSettings.resizableWindow = false;//可变的窗口尺寸(限制窗口的可变性)
            PlayerSettings.bundleVersion = GetBundleVersion();
            PlayerSettings.displayResolutionDialog = ResolutionDialogSetting.Disabled;
            PlayerSettings.SetScriptingDefineSymbolsForGroup(BuildTargetGroup.Standalone, defines);
            BuildPipeline.BuildPlayer(GetBuildScenes(), path, BuildTarget.StandaloneWindows, BuildOptions.None);
        }


        static string GetBundleVersion()
        {
            return DateTime.Now.ToString().Split(' ')[0].Replace('/', '.');
        }
    }
}
